<?php

class Io extends Api
{
    protected $noNeedLogin = ['add'];
    public function add()
    {
        //`type`,
        // `source`,
        // `state`,
        // `phone`,
        // `search`,
        // `brand`,
        // `path`,
        // `u_pid`,
        // `u_id`,
        // `remark`,
        // `created_at`,
        // `update_at`
        //$type = $this->getParam('type');
        $source = $this->getParam('source');
        $state = $this->getParam('state');
        $phone = $this->getParam('phone');
        $search = $this->getParam('search');
        $brand = $this->getParam('brand');
        $path = $this->getParam('path');
        $ip = $this->getParam('ip');
        $path_f = $this->getParam('path_f');
        $u_pid = $this->getParam('u_pid');
        $u_id = $this->getParam('u_id');
        $remark = $this->getParam('remark');
        $created_at = $this->getParam('created_at');
        $update_at = $this->getParam('update_at');
        $source_index = array_search($source, CrmConst::SOURCE);
        if ($source_index === false) {
            $source_index = 0;
        }
        $util = new BelongingToLocal();
        $address_ip = ($util->useIp($ip));
        $address_phone = ($util->useTel($phone));
        $data = [
            'type' => 0,
            'source' => $source_index,
            'source_type' => 0,
            'state' => 0,
            'phone' => $phone,
            'search' => $search,
            'brand' => $brand,
            'path' => $path,
            'ip' => $ip,
            'address_ip' => $address_ip['res'] ? ($address_ip['area'] . "-" . $address_ip['city']) : '',
            'address_phone' => $address_phone['res'] ? ($address_phone['area'] . "-" . $address_phone['city']) : '',
            'path_f' => $path_f,
            'created_at' => time()
        ];
        $res = $this->getDb()->insert('infos', $data);
    }

}
